<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 准备好容器 -->
    <div id="test">
    </div>
</body>
<!-- 引入依赖 引入的时候，必须就按照这个步骤-->
<script src="../React-js/react.development.js" type = "text/javascript"></script>
<script src = "../React-js/react-dom.development.js" type = "text/javascript"></script>
<script src="../React-js/babel.min.js" type="text/javascript"></script>


<script type="text/babel">
    class Count extends React.Component{
        // 构造器
        constructor(props){
            console.log('constructor')
            super(props)
            // 初始化状态
            this.state = {count:0}
        }
        // 组件将要挂载
        componentWillMount(){
            console.log('componentWillMount')
        }
        // 组件挂完毕
        componentDidMount(){
            console.log('componentDidMount')
        }
        // 组件将要卸载
        componentWillUnmount(){
            console.log('componentWillUnmount')
        }
        // 控制组件更新的阀门
        shouldComponentUpdate(){
            console.log('shouldComponentUpdate')
            return false
        }
        // 组件将要更新
        componentWillUpdate(){
            console.log('componentWillUpdate')
        }
        // 组件完成更新
        componentDidUpdate(){
            console.log('componentDidUpdate')
        }
        
        add = ()=>{
            const {count} = this.state
            this.setState({count:count+1})

        }
        force = ()=>{
            this.forceUpdate()

        }
        render(){
            console.log('render')
            const {count} = this.state
            return(
                <div>
                    <h2>当前求和:{count}</h2>
                    <button onClick={this.add} >点我+1</button>
                    <button onClick={this.force} >强制更新</button>       
                </div>
            )
        }
    }

    ReactDOM.render(<Count/>,document.getElementById("test"))
</script>
</html>